package cn.edu.scau.cmi.luodongmei.gui;

import cn.edu.scau.cmi.luodongmei.composite.safe.China;
import cn.edu.scau.cmi.luodongmei.composite.safe.USA;
import cn.edu.scau.cmi.luodongmei.composite.safe.WorldOrganization;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.geometry.Pos;
import javafx.scene.control.ChoiceBox;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
import javafx.scene.text.Text;

public class SafeCompositeGUI extends Pane{
	WorldOrganization wo = null;
	public SafeCompositeGUI() {
		BorderPane borderPane = new BorderPane();
		borderPane.setPrefSize(500, 300);
		
		Text selectType = new Text("请选择国家");
		Text info = new Text();
		info.setFont(Font.font ("Verdana", 20));
		
		ChoiceBox<Object> cb = new ChoiceBox<>();
		cb.setItems(FXCollections.observableArrayList(
		    "中国", "美国 ")
		);
		cb.getSelectionModel().selectedIndexProperty().addListener(
				(ObservableValue<? extends Number> ov,
						Number old_val, Number new_val) -> {
							switch(new_val.intValue()) {
							case 0: 
								wo = new China();
								break;
							case 1:
								wo = new USA();
								break;
							default:
							}
							if(wo != null) {
								info.setText(wo.say());
							}
		});
		
		HBox hbox = new HBox();
		hbox.getChildren().addAll(selectType,cb);
		hbox.setAlignment(Pos.CENTER);
		hbox.setSpacing(10);
		
		VBox vbox = new VBox();
		vbox.getChildren().addAll(hbox,info);
		vbox.setAlignment(Pos.CENTER);
		vbox.setSpacing(10);
		
		borderPane.setCenter(vbox);
		getChildren().add(borderPane);
	}
}
